//
//  BaseViewController.m
//  phmall
//
//  Created by admin on 2017/11/17.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()<UITabBarControllerDelegate>
@property(nonatomic,assign) NSUInteger selectedIndex;
@end

@implementation BaseViewController
-(void)leftBarAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }

    self.back=[[UIView alloc]init];
    [self.view addSubview:self.back];
    self.back.backgroundColor=[UIColor whiteColor];
    [self.back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(-(STATUS_BAR_HEIGHT+44));
        make.height.offset(STATUS_BAR_HEIGHT+44);
    }];
    
    self.view.backgroundColor=[UIColor colorWithRed:0.98f green:0.98f blue:0.98f alpha:1.00f];
    if (SCREEN_HEIGHT==812) {
        self.tabBar_height=34;
    }else{
        self.tabBar_height=0;
    }
    NSLog(@"%f",self.tabBar_height);

    // Do any additional setup after loading the view.
}
-(void)userLogout{
    YYCache *userCache=[YYCache cacheWithName:@"user"];
    [userCache removeAllObjects];
    YYCache *cartCache = [YYCache cacheWithName:@"cart"];
    [cartCache removeAllObjects];
    YYCache *addressCache = [YYCache cacheWithName:@"address"];
    [addressCache removeAllObjects];
 
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:[NSNumber numberWithBool:NO]];
}
-(void)whetherLogin{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"账号未登录" message:@"是否前往登录" preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击取消");
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:[NSNumber numberWithBool:NO]];
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
}

#pragma mark - tabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    self.selectedIndex=tabBarController.selectedIndex;
    if (tabBarController.selectedIndex==3||tabBarController.selectedIndex==4) {
        YYCache *cache = [YYCache cacheWithName:@"user"];
        if (![cache containsObjectForKey:@"userInfo"]) {
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:[NSNumber numberWithBool:NO]];
            [self.navigationController.tabBarController setSelectedIndex:0];
        }
        return;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
